<template>
  <!-- 战败车型 -->
  <div class="orderManage">
    <TopFilter
      ref="TopFilter"
      :list="topFilterList"
      :cols="3"
      labelWidth="100"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>
    <p style="line-height: 40px;background: #f2f2f2;padding-left: 10px;">预约信息</p>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      columnsRef="potenCus_customer_orderManage_index_01"
    >
      <template slot="controls">
        <!-- <el-button size="small" type="primary" icon="el-icon-download" :loading="excelLoding" @click="downloadExcelFnc">导出</el-button> -->
        <multiuse-button
          size="small"
          type="primary"
          :click="downloadExcelFnc"
          :auth-list="auths"
          :loading="excelLoding"
          auth-mark="/api/clue/appoint/export/excel"
        >导出</multiuse-button>
      </template>
    </FilterTable>

    <BaseDialog
      :visible.sync="isShow"
      :title="title"
      destroyOnClose
      :width="widthDialog"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto'}"
    >
      <div class="pot" v-if="title == '客流登记'?true:false">
        <!-- <FormPanel ref="FormPanel" :cols='2' class="orderManageFormPanel" :list="formList" formType="add" :isSubmitBtn="false" />
            <div style="text-align: center;">
              <el-button  type="primary" @click="formChangeHandle">保存</el-button>
              <el-button  type="primary" @click="closeHandler(false)">取消</el-button>
        </div>-->
        <exhibitionModal
          :rowData="formData"
          :RolePosition="RolePosition"
          :type="typeAdd"
          :typeEdit="typeEdit"
          @close="closeHandler(false,'refresh')"
        />
      </div>
      <!-- <div v-else>
          <FormPanel
            :list="topFilterList2"
            :cols="2"
            :isSubmitBtn="false"
          ></FormPanel>
          <div style="text-align: center;">
            <el-button  type="primary" @click="formChangeHandle">保存</el-button>
            <el-button  type="primary" @click="closeHandler(false)">取消</el-button>
          </div>
      </div>-->
      <div v-else>
        <FormPanel :list="topFilterList2" :cols="2" :isSubmitBtn="false"></FormPanel>
        <div style="text-align: center;">
          <el-button type="primary" @click="editConfirm">确 定</el-button>
        </div>
      </div>
    </BaseDialog>

    <!-- 计划跟进 -->
    <el-dialog :visible.sync="visible" title="跟进" width="90%">
      <followModal
        v-if="visible"
        :type="type"
        :typeEdit="typeEdit"
        :rowData="formData"
        @fatherClose="fatherClose"
        @close="closeHandler(false,'refresh')"
      />
    </el-dialog>

    <!-- 编辑潜客 -->
    <Drawer
      :visible.sync="isShowClues"
      :title="title"
      width="80%"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <cluesModel
        v-if="isShowClues"
        type="orderAdd"
        :RolePosition="RolePosition"
        :rowData="formData"
        @close="closeHandler_clues"
      />
    </Drawer>
  </div>
</template>

<script>
import { queryorderManage, cancelAppoint, updateAppointInfo, saveReceptionist, getConsultant, exportAppointmentExcel } from '@/api/potenCus/customer/orderManage';
import { dictionary } from '@/utils/dictMixin';
import followModal from '../../customer/customerFollowInfo/tabs/followModal';
import cluesModel from '../../customer/potenCusManage/cluesModel';
import { getUserInfoByRolePosition, getUserInfo } from '@/api/potenCus/customer/exhibition';
import { authority } from '@/utils/authMixin';
import { formatDates_minute } from '@/utils/validate';
import exhibitionModal from '../exhibition/modal';
import { getDataType } from '@/assets/js/auth';
import { exportExcelFile } from '@/utils';
export default {
  // name: 'orderManage',
  name: 'orderManage',
  mixins: [dictionary, authority],
  components: {
    followModal,
    exhibitionModal,
    cluesModel
  },
  data() {
    return {
      dataType: getDataType('dataType'),
      title: '修改预约时间',
      widthDialog: '30%',
      value: '',
      visible: false,
      pickerOptions: {
        shortcuts: [
          {
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          },
          {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          },
          {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }
        ]
      },
      topFilterList: this.createTopFilters(),
      topFilterList2: this.createTopFilters2(),
      formList: this.createFormList(),
      fetchParams: {
        invitationsDate: this.$route.query.active ? Date.parse(this.$route.query.time) / 1000 : undefined,
        invitationsDateEnd: this.$route.query.active ? Date.parse(this.$route.query.time) / 1000 : undefined,
        isArrived: this.$route.query.active == 2 || this.$route.query.active == 3 ? 70171003 : undefined,
        consultant: this.$route.query.active ? [this.$route.query.consultant] : undefined
      },
      isShow: false,
      isShowClues: false, //跳转编辑潜客
      formData: {},
      fetchApi: queryorderManage,
      columns: this.createTableColumns(),
      handleType: '',
      page: {
        pageNum: 1,
        currentPage: 1,
        pageSize: 20,
        limit: 20
      },
      actionId: '',
      taskId: '',
      RolePosition: [],
      isNow: '',
      typeAdd: 'add',
      type: 'orderAdd',
      typeEdit: '',
      roleType: localStorage.getItem('roleType'),
      excelLoding: false
    };
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '客户名称'
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'contectName',
          placeholder: '联系人'
        },
        {
          type: 'SELECT',
          label: '意向级别',
          fieldName: 'intentLevel',
          placeholder: '请选择',
          itemList: this.createDictList('1519')
        },
        {
          type: 'SELECT',
          label: '所属顾问',
          fieldName: 'consultant',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'RANGE_DATE',
          label: '预约时间',
          fieldName: 'invitationsDate|invitationsDateEnd',
          placeholder: '请输入',
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          type: 'SELECT',
          label: '预约状态',
          fieldName: 'isArrived',
          placeholder: '请选择',
          itemList: this.createDictList('7017')
        },
        {
          type: 'SELECT',
          label: '预约类型',
          fieldName: 'appointmentType',
          placeholder: '请选择',
          itemList: this.createDictList('7069')
        }
      ];
    },
    createTopFilters2() {
      return [
        {
          type: 'DATE',
          label: '预约时间',
          fieldName: 'appointTime',
          placeholder: '请输入...',
          initialValue: '',
          dateType: 'datetime',
          style: { width: '200px' },
          rules: [{ required: true, message: '请选择预约时间', trigger: 'change' }]
        }
      ];
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '客户名称'
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'mobilePhone',
          placeholder: '手机号'
        },
        {
          type: 'SELECT',
          label: '展厅顾问',
          fieldName: 'consultant',
          placeholder: '请选择',
          itemList: [],
          rules: [{ required: true, message: '请选择展厅顾问', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '性别',
          fieldName: 'gender',
          placeholder: '请选择',
          itemList: this.createDictList('1002')
          // itemList: [{ text: '先生', value: '10021001' }, { text: '女士', value: '10021002' }, { text: '未知', value: '10021003' }],
          // render: props => {
          //    return <span>{this.createDictText(parseInt(props.row.gender), '1002')}</span>;
          // }
        },
        {
          type: 'DATE_TIME',
          label: '进店时间',
          fieldName: 'invitationsDate1',
          placeholder: '请输入',
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd',
          rules: [{ required: true, message: '请选择进店时间', trigger: 'change' }]
        },
        {
          type: 'DATE_TIME',
          label: '离店时间',
          fieldName: 'leaveTime',
          placeholder: '请输入',
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd',
          hidden: false
          // rules: [{ required: true, message: '请选择离店时间', trigger: 'change' }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '进店人数',
          fieldName: 'arrivePeopleNum',
          placeholder: '请选择',
          rules: [{ required: true, message: '请输入进店人数', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          placeholder: '请选择'
          // style: { width: '232%' }
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 160,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button
                  size="mini"
                  disabled={props.row.isArrived == 70171003 ? false : true}
                  type="text"
                  onClick={() => this.confirmHandle(props.row)}
                  auth-list={this.auths}
                  auth-mark={'/api/cyxdms.clue/receptionist/saveReceptionist'}
                >
                  确认到店
                </multiuse-button>
                <multiuse-button
                  size="mini"
                  disabled={props.row.isArrived == 70171003 ? false : true}
                  type="text"
                  onClick={() => this.cancleHandle(props.row)}
                  auth-list={this.auths}
                  auth-mark={'/api/cyxdms.clue/appoint/cancelAppoint'}
                >
                  取消
                </multiuse-button>
                <multiuse-button
                  size="mini"
                  disabled={props.row.isArrived == 70171003 ? false : true}
                  type="text"
                  onClick={() => this.editHandle(props.row)}
                  auth-list={this.auths}
                  auth-mark={'/api/cyxdms.clue/appoint/updateAppointInfo'}
                >
                  修改
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },

        {
          title: '客户编号',
          dataIndex: 'customerNo',
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType',
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: props => {
            return <span>{this.createDictText(props.row.customerType, '1523')}</span>;
          }
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'input'
        },
        {
          title: '联系人姓名',
          dataIndex: 'contectName',
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'gender',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1002'),
          render: props => {
            return <span>{this.createDictText(props.row.gender, '1002')}</span>;
          }
        },
        {
          title: '手机号',
          dataIndex: 'mobilePhone',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '意向级别',
          dataIndex: 'intentLevel',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1519'),
          render: props => {
            return <span>{this.createDictText(props.row.intentLevel, '1519')}</span>;
          }
        },
        {
          title: '预约类型',
          dataIndex: 'appointmentType',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7069'),
          render: props => {
            return <span>{this.createDictText(props.row.appointmentType, '7069')}</span>;
          }
        },
        {
          title: '预约日期',
          dataIndex: 'invitationsDate',
          sorter: true,
          align: 'center',
          render: props => {
            return <span>{formatDates_minute(props.row.invitationsDate)}</span>;
          }
        },
        // {
        //   title: '预约时段',
        //   dataIndex: 'period',
        //   sorter: true,
        //   align: 'center',
        // },
        {
          title: '到店时间',
          dataIndex: 'factActionDate',
          sorter: true,
          align: 'center',
          render: props => {
            return <span>{formatDates_minute(props.row.factActionDate)}</span>;
          }
        },
        {
          title: '预约状态',
          dataIndex: 'isArrived',
          width: 200,
          sorter: true,
          filter: true,
          align: 'center',
          filterType: 'checkbox',
          filterItems: this.createDictList('7017'),
          render: props => {
            return <span>{this.createDictText(props.row.isArrived, '7017')}</span>;
          }
        },
        {
          title: '所属顾问',
          dataIndex: 'consultantName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    // addHandle() {
    //   this.handleType = 'add';
    //   // this.showHandler();
    // },
    init() {
      // 首页报表进入时处理
      // switch (this.$route.query.active) {
      //   case 1:
      //     this.topFilterList.find(item => item.fieldName === 'invitationsDate|invitationsDateEnd').initialValue = [this.$route.query.time, this.$route.query.time];
      //     setTimeout(() => {
      //       this.$refs.TopFilter.SUBMIT_FORM();
      //     }, 400);
      //     break;
      //   case 2:
      //     this.topFilterList.find(item => item.fieldName === 'invitationsDate|invitationsDateEnd').initialValue = [this.$route.query.time, this.$route.query.time];
      //     this.topFilterList.find(item => item.fieldName === 'isArrived').initialValue = 70171003;
      //     setTimeout(() => {
      //       this.$refs.TopFilter.SUBMIT_FORM();
      //     }, 400);
      //     break;
      //   case 3:
      //     this.topFilterList.find(item => item.fieldName === 'invitationsDate|invitationsDateEnd').initialValue = [this.$route.query.time, this.$route.query.time];
      //     this.topFilterList.find(item => item.fieldName === 'isArrived').initialValue = 70171003;
      //     setTimeout(() => {
      //       this.$refs.TopFilter.SUBMIT_FORM();
      //     }, 400);
      //     break;
      //   case 4:
      //     this.topFilterList.find(item => item.fieldName === 'invitationsDate|invitationsDateEnd').initialValue = [this.$route.query.time, this.$route.query.time];
      //     setTimeout(() => {
      //       this.$refs.TopFilter.SUBMIT_FORM();
      //     }, 400);
      //     break;
      //   default:
      //     break;
      // }
      // getConsultant(this.fetchParams).then(res=>{
      //     this.topFilterList[3].itemList=res.data
      //     this.formList[2].itemList=res.data
      //     console.log( this.formList," this.topFilterList2")
      // })

      // 查询销售顾问
      this.getConsultant(1, this.dataType === 'clue' ? '10061012' : '10061012,10061015').then(result => {
        console.log('顾问列表:', result);
        this.topFilterList[3].itemList = result;
        this.formList[2].itemList = result;
        this.RolePosition = result;
      });
      /* getUserInfo().then(res => {
          if(res.resultCode == 200){
            let param = {
              companyId:res.data.userInfo.companyId,
              positionCode:10061015
            };
            getUserInfoByRolePosition(param).then(res => {
              if(res.resultCode == 200){
                this.RolePosition=res.data.map(x => ({ value: x.userId, text: x.employeeName ,orgId:x.orgId}))
                // this.RolePosition=_.uniqBy(this.RolePosition,'value')
                this.topFilterList[3].itemList = this.RolePosition
                this.formList[2].itemList=this.RolePosition
              }else{
                this.$message.error('获取人员列表失败!');
              }
            })
          }else{
            this.$message.error('获取当前登录用户信息失败!');
          }
        }); */
    },
    confirmHandle(row) {
      this.isShow = true;
      console.log('确认到店', row);
      this.employeeNo = row.consultant;
      this.title = '客流登记';
      this.widthDialog = '50%';
      this.typeEdit = 'typeEdit';
      this.formData = row;
      /* this.formList.forEach(x=>{
          x.initialValue=row[x.fieldName]
        }) */
      this.taskId = row.actionId;
      if (row.isArrived == 70171003) {
        let time = new Date(); //根据时间戳生成的时间对象
        let year = time.getFullYear();
        let month = time.getMonth() + 1;
        // let date = time.getDate()+1;
        let date = time.getDate();
        let hours = time.getHours();
        let minutes = time.getMinutes();
        let seconds = time.getSeconds();
        this.formList[4].initialValue = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
      }
      if (row.consultant == 10061011) {
        //如果是前台接待让其不能编辑
        this.formList[5].hidden = true;
        this.formList[5].initialValue = '';
      }

      // 判断是前台接待还是展厅顾问
      this.roleType.split(',').forEach(x => {
        if (x == '10061011') {
          //前台接待consultant
          this.formList.find(item => item.fieldName === 'consultant').initialValue = '';
          // this.formList[2].initialValue
        }
        if (x == '10061015') {
          //展厅顾问
          this.formList.find(item => item.fieldName === 'consultant').initialValue = row.consultant;
        }
        if (x == 'null') {
          this.formList.find(item => item.fieldName === 'consultant').initialValue = '';
        }
      });
    },
    //确认到店保存
    formChangeHandle() {
      // this.$refs.FormPanel.SUBMIT_FORM()
      // console.log(this.formList,"this.$refs.FormPanel.SUBMIT_FORM()")
      if (this.formList.find(item => item.fieldName === 'consultant').initialValue == '' || this.formList.find(item => item.fieldName === 'invitationsDate1').initialValue == undefined) {
        this.$message({
          type: 'info',
          message: '请选择必填项'
        });
      } else {
        if (this.formList.find(item => item.fieldName === 'arrivePeopleNum').initialValue == 0) {
          this.formList.find(item => item.fieldName === 'arrivePeopleNum').initialValue = '';
          this.$message({
            type: 'info',
            message: '进店人数不能为0'
          });
        } else {
          let params = {
            arrivePeopleNum: '',
            consultant: '',
            customerName: '',
            gender: '',
            orgId: '',
            // invitationsDate1: '',
            leaveTime: '',
            mobilePhone: '',
            remark: '',
            buttonType: 3,
            taskId: this.taskId,
            actionId: this.taskId,
            // employeeNo:this.employeeNo,
            employeeNo: '',
            receptionConsultant: ''
          };

          this.formList.forEach(x => {
            Object.keys(params).map(k => {
              if (x.fieldName == k) {
                params[k] = x.initialValue;
              }
            });
          });

          this.formList
            .find(item => item.fieldName === 'consultant')
            .itemList.forEach(x => {
              if (params.consultant == x.value) {
                params.orgId = x.orgId;
              }
            });
          // params.customerName=params.consultant
          params.receptionConsultant = params.consultant;
          params.employeeNo = params.consultant;
          // params.invitationsDate1=Date.parse(this.formList[4].initialValue)
          // params.taskId=this.taskId
          params.arriveDate = Date.parse(this.formList[4].initialValue);
          params.leaveTime = Date.parse(this.formList[5].initialValue);

          let arriveDate1 = new Date(params.arriveDate);
          let leaveTime2 = new Date(params.leaveTime);
          // let leaveTime3 = new Date(Date.parse(this.formList[7].initialValue));
          // 进店时间
          let arriveDateYear1 = arriveDate1.getFullYear();
          let arriveDateMonth1 = arriveDate1.getMonth();
          let arriveDateDate1 = arriveDate1.getDate();
          // 离店时间1
          let leaveTimeYear2 = leaveTime2.getFullYear();
          let leaveTimeMonth2 = leaveTime2.getMonth();
          let leaveTimeDate2 = leaveTime2.getDate();
          let isHaveLeaveTim = false;
          let d = new Date();

          console.log(Date.parse(d), 'Date.parse(d)', params.leaveTime);
          if (params.leaveTime > 0) {
            isHaveLeaveTim = true;
          } else {
          }
          if (isHaveLeaveTim) {
            if (params.leaveTime < params.arriveDate) {
              this.$message({
                message: '离店时间应大于进店时间',
                type: 'warning'
              });
            } else if (arriveDateYear1 != leaveTimeYear2) {
              this.$message({
                message: '离店时间必须与进店时间为同一天',
                type: 'warning'
              });
            } else if (arriveDateMonth1 != leaveTimeMonth2) {
              this.$message({
                message: '离店时间必须与进店时间为同一天',
                type: 'warning'
              });
            } else if (arriveDateDate1 != leaveTimeDate2) {
              this.$message({
                message: '离店时间必须与进店时间为同一天',
                type: 'warning'
              });
            } else if (params.leaveTime > Date.parse(d)) {
              this.$message({
                message: '离店时间必须小于当前时间',
                type: 'warning'
              });
            } else {
              saveReceptionist(params).then(res => {
                // console.log(res,"Res123")
                if (res.resultCode == 200) {
                  this.closeHandler(false, 'refresh');
                }
              });
            }
          } else {
            saveReceptionist(params).then(res => {
              // console.log(res,"Res123")
              if (res.resultCode == 200) {
                this.closeHandler(false, 'refresh');
              }
            });
          }

          /* if(params.leaveTime < params.arriveDate){
                this.$message({
                  type: 'info',
                  message: '离店时间不能小于进店时间'
                });
            }else{
              saveReceptionist(params).then(res=>{
                // console.log(res,"Res123")
                if(res.resultCode == 200){
                  this.closeHandler(false,'refresh')
                }
              })
            } */
        }
      }
    },
    editHandle(row) {
      this.isShow = true;
      console.log('修改', row);
      this.title = '修改预约时间';
      this.widthDialog = '50%';
      this.actionId = row.actionId;
      this.formData = row;
      this.formData.actionId = row.actionId;
      if (row.planActionDate) {
        let d = new Date(Number(row.planActionDate)); //根据时间戳生成的时间对象
        let dateString = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
        this.formData.planActionDate = dateString;
      } else {
        this.formData.planActionDate = '';
      }

      let time = new Date(); //根据时间戳生成的时间对象
      let year = time.getFullYear();
      let month = time.getMonth() + 1;
      let dateNow = time.getDate() > 9 ? time.getDate() : '0' + time.getDate();
      let date = time.getDate() > 9 ? time.getDate() : '0' + time.getDate();
      let hours = time.getHours() > 9 ? time.getHours() : '0' + time.getHours();
      let minutes = time.getMinutes() > 9 ? time.getMinutes() : '0' + time.getMinutes();
      let seconds = time.getSeconds() > 9 ? time.getSeconds() : '0' + time.getSeconds();

      this.isNow = `${year}-${month}-${dateNow} ${hours}:${minutes}:${seconds - 5 > 0 ? seconds - 5 : 0}`;
      this.topFilterList2[0].initialValue = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
      this.typeEdit = 'typeEdit';
      // this.handleType = 'edit';
      // this.formData = row;
      // this.showHandler();
    },
    //修改的确定
    editConfirm() {
      console.log(this.topFilterList2[0].initialValue, this.isNow, Date.parse(this.topFilterList2[0].initialValue), 'this.topFilterList2[0].initialValue', Date.parse(this.isNow));
      if (Date.parse(this.topFilterList2[0].initialValue) > Date.parse(this.isNow)) {
        [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(x => {
          let arriveDateEndM = '';
          if (this.topFilterList2[0].initialValue.split('-')[1] == x && this.topFilterList2[0].initialValue.split('-')[1].length == 1) {
            arriveDateEndM = '0' + this.topFilterList2[0].initialValue.split('-')[1];
            this.topFilterList2[0].initialValue = `${this.topFilterList2[0].initialValue.split('-')[0]}-${arriveDateEndM}-${this.topFilterList2[0].initialValue.split('-')[2]}`;
          }
        });

        updateAppointInfo(this.actionId, this.topFilterList2[0].initialValue).then(res => {
          console.log(res, 'res');
          if (res.resultCode == 200) {
            if (res.data == null) {
              this.$message({
                type: 'success',
                message: '修改成功!'
              });
              this.closeHandler(false, 'refresh');
            } else {
              // this.visible=true
              this.open2();
            }
          }
        });
      } else {
        this.$message({
          message: '修改时间要大于当前时间',
          type: 'warning'
        });
      }
    },
    open2() {
      this.$confirm('是否登记本次跟进?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.visible = true;
        })
        .catch(() => {
          this.closeHandler(false, 'refresh');
          // this.$message({
          //   type: 'info',
          //   message: ''
          // });
        });
    },
    cancleHandle(row) {
      this.open(row);
      // this.handleType = 'show';
      // this.formDataDetail = row;
      // this.showHandlerDetail();
    },
    //取消
    open(row) {
      console.log('取消', row);
      this.$confirm('你确定取消吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          cancelAppoint(row.actionId).then(res => {
            console.log(res, 'Res');
            if (res.resultCode == 200) {
              if (res.data == null) {
                this.$message({
                  type: 'success',
                  message: '取消成功!'
                });
                this.closeHandler(false, 'refresh');
              } else {
                this.formData = row;
                this.open2();
                // this.visible=true
              }
            }
          });
        })
        .catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: ''
          // });
        });
    },
    changeHandle(val) {
      console.log(val, 'val56');
      let params = {
        isArrived: val.isArrived,
        consultant: val.consultant,
        contectName: val.contectName,
        customerName: val.customerName,
        intentLevel: val.intentLevel,
        invitationsDate: !Date.parse(val.invitationsDate) ? '' : Date.parse(val.invitationsDate) / 1000,
        invitationsDateEnd: !Date.parse(val.invitationsDateEnd) ? '' : Date.parse(val.invitationsDateEnd) / 1000,
        appointmentType: val.appointmentType
        // "invitationsDate|invitationsDateEnd":'"'+Date.parse(val.invitationsDate)+"|"+Date.parse(val.invitationsDate)+'"'
      };
      if (val.isArrived || val.consultant || val.contectName || val.customerName || val.intentLevel || val.invitationsDate || val.invitationsDateEnd || val.appointmentType) {
        this.fetchParams = Object.assign(params, {});
        //this.fetchParams = params;
      } else {
        this.fetchParams = Object.assign({ pageNum: 1, currentPage: 1, pageSize: 20, limit: 20 }, {});
        //this.fetchParams = { pageNum: 1, currentPage: 1, pageSize: 20, limit: 20 };
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    closeHandler_clues() {
      this.isShowClues = false;
      // 重新加载
      this.fetchParams = { ...this.fetchParams };
    },
    fatherClose(val) {
      console.log('andFollow来的', val);
      this.formData = val.data;
      this.isShow = false;
      this.visible = false;
      this.isShowClues = true;
      this.title = '编辑潜客';
    },
    closeHandler(val, type) {
      this.isShow = val;
      this.visible = false;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    downloadExcelFnc() {
      this.excelLoding = true;
      this.$nextTick(() => {
        exportAppointmentExcel(this.fetchParams).then(res => {
          exportExcelFile(res.data, '预约信息');
          this.excelLoding = false;
        });
      });
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    if (this.$route.query.time) {
      this.topFilterList.find(item => item.fieldName === 'invitationsDate|invitationsDateEnd').initialValue = [this.$route.query.time, this.$route.query.time];
    }
    if (this.$route.query.consultant) {
      this.topFilterList.find(item => item.fieldName === 'consultant').initialValue = this.$route.query.consultant;
    }
    this.init();
  },
  created() {}
};
</script>

<style lang="less">
// .pot{
//   position: relative;
//   .orderManageFormPanel{
//   .el-form .el-row:last-child .el-col {
//     position: relative;
//     left: 30%;
//     .el-form-item__content .el-button:last-child{
//       display: none;
//     }
//   }
// }
// }
</style>
